package com.ga.config;

import com.ga.controller.AlbumController;
import com.ga.controller.BmIndexController;
import com.ga.controller.IndexController;
import com.ga.controller.ReplyController;
import com.ga.controller.UsersController;
import com.ga.controller.VideoController;
import com.ga.model.Album;
import com.ga.model.Reply;
import com.ga.model.User;
import com.ga.model.Video;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.ehcache.EhCachePlugin;
import com.jfinal.render.ViewType;

public class GaConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		loadPropertyFile("jdbc.properties");
		me.setDevMode(true);
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configHandler(Handlers handle) {
		
	}

	@Override
	public void configInterceptor(Interceptors me) {
		
	}

	@Override
	public void configPlugin(Plugins me) {
		initDB(me);

	}

	public void configRoute(Routes me) {
		me.add("/", IndexController.class, "/pages");
		me.add("/user", UsersController.class, "/pages");
		me.add("/album", AlbumController.class, "/pages");
		me.add("/vido", VideoController.class, "/pages");
		me.add("/reply", ReplyController.class, "/pages");
		me.add("/bm", BmIndexController.class, "/pages");
	}

	private void initDB(Plugins me) {
		DruidPlugin druidPlugin = new DruidPlugin(getProperty("jdbc.url"), getProperty("jdbc.username"), getProperty("jdbc.password"), getProperty("jdbc.driverClassName"));
		druidPlugin.setInitialSize(3).setMaxActive(10);
		me.add(druidPlugin);
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
		arp.setShowSql(true);

		arp.addMapping("users", User.class);
		arp.addMapping("reply", Reply.class);
		arp.addMapping("album", Album.class);
		arp.addMapping("video", Video.class);
		me.add(arp);
		// 缓存插件
		// me.add(new EhCachePlugin());

	}

}
